import { defineStore } from 'pinia'
import { getMyUserInfo } from '@/api/user'

const useUserInfo = defineStore('userInfo', {
  state: () => {
    return {
      avatar: '',//头像
      sex: 0,//性别，
      sign: '',//简介
      name: ''//姓名
    }
  },
  actions: {
    setUserInfo(data) {
      this.avatar = data.avatar
      this.sex = data.sex
      this.sign = data.sign
      this.name = data.name
    },
    async getUserInfo() {
      //拿到用户信息
      let data = (await getMyUserInfo()).data
      this.avatar = data.avatar
      this.sex = data.sex
      this.sign = data.sign
      this.name = data.name
    }
  }
})
export default useUserInfo
